<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use dektrium\user\models\User;
use app\modules\Order\models\Order;
use app\modules\Product\models\Product;
// 获取所有销售
$data = [];

$user = Order::find()->select('user_id')->groupBy('user_id')->all();
if($user){
	foreach($user as $u){
		$ret  = User::findOne($u->user_id);
		$data[$u->user_id] = isset($ret->profile->name) ? $ret->profile->name : '';
	}
}

$product = [];
$time = date("Y-m-d", strtotime("-3 month"));
//$time = date("Y-m-d");
$arr = Product::find()->where(['>=','go_time', $time])->andWhere(['status'=>1])->orderBy('go_time')->all();
if($arr){
    foreach($arr as $r){
        $product[$r->id] = $r->code.' '.$r->cruise->name.' '.$r->go_time.' '.$r->name;
    }
}


//$user = User::find()->all();
//if($user){
//	$data = \yii\helpers\ArrayHelper::map($user, 'id', function($model){ return $model->profile->name;} );
//}

?>
<style type="text/css">
	.field-ordersearch-status {min-width:130px;}
	.form-inline .form-group{margin-bottom: 15px;}
</style>

<div class="order-search">
    <?php $form = ActiveForm::begin([
        'action' => ['my-index'],
        'method' => 'get',
        'layout' => 'inline',
        'options' => ['data-pjax'=>true],
    ]); ?>

	<?php if(Yii::$app->user->can('order_all')){ ?>
    <?= $form->field($model, 'member_id')->dropdownList($data, ['prompt'=>'选择销售']) ?>
	<?php } ?>

    <!-- ?= $form->field($model, 'product_id')->dropdownList($product, ['prompt'=>'选择船期', 'style'=>'width:170px;']) ? -->

	<?= $form->field($model, 'product_id')->widget(kartik\select2\Select2::classname(), [
						'data' =>  $product, //	Yii::$app->params['order_status'],
						'options' => [
							'multiple' => true,
							'placeholder' => '选择船期',
						],
						'pluginOptions' => [
							'tags' => true,
							//'closeOnSelect' =>  false,  //  选择后不消失
							'maximumInputLength' => 10,
							'allowClear' => true,
							'width' => "600px",
						],
					]);
	?>

    <?= $form->field($model, 'code')->textInput(['placeholder' => Yii::t('app.order', 'Code')]) ?>

    <?= $form->field($model, 'source')->dropdownList(Yii::$app->params['order_source'], ['prompt'=>Yii::t('app.order', 'Source')]) ?>

    <!-- ?= $form->field($model, 'status')->dropdownList(Yii::$app->params['order_status'], ['prompt'=>'全部']) ? -->
	<?= $form->field($model, 'status')->widget(kartik\select2\Select2::classname(), [
						'data' => Yii::$app->params['order_status'],
						'options' => [
							'multiple' => true,
							'width' => "150%",
							'placeholder' => '选择订单状态',
						],
						'pluginOptions' => [
							'tags' => true,
							'closeOnSelect' =>  false,  //  选择后不消失
							'maximumInputLength' => 10
						],
					]);
	?>
    <!-- ?= $form->field($model, 'created_at')->widget(kartik\date\DatePicker::classname(),[
                                                'options' => ['placeholder' => Yii::t('app.order', 'Created At')],
                                                'pluginOptions' => [
                                                    'format' => 'yyyy-mm-dd',
                                                    'autoclose'=>true,
                                                    'todayHighlight' => true
                                                ]
                                            ]); ? -->

    <?= $form->field($model, 'username')->textInput(['placeholder' => Yii::t('app.order', 'Username'), 'style'=>'width:140px;']) ?>

    <?= $form->field($model, 'company')->textInput(['placeholder' => Yii::t('app.order', 'Company'), 'style'=>'width:140px;']) ?>
	
    <div class="form-group">
        <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
